package util;

/**
 * 字符处理工具类
 * 
 * @author zhangzuoqiang <br/>
 *         Date: Aug 25, 2011
 */
public class StringUtils {

	/**
	 * 判断是否是空字符串
	 * 
	 * @param s
	 * @return
	 */
	public static boolean isEmptyString(String s) {
		return ((s == null) || (s.length() == 0));
	}

	/**
	 * 移除字符串头部空格
	 * 
	 * @param in
	 * @return
	 */
	public static String removeLeadingSpaces(String in) {
		return in.replaceAll("^[\\s]+", "");
	}

	/**
	 * 移除字符串尾部空格
	 * 
	 * @param in
	 * @return
	 */
	public static String removeTrailingSpaces(String in) {
		return in.replaceAll("[\\s]+$", "");
	}

	/**
	 * 移除字符串中所有的空格
	 * 
	 * @param in
	 * @return
	 */
	public static String cleanupSpaces(String in) {
		return in.replaceAll("[\\s]", "");
	}

	/**
	 * 移除字符串头部空格和尾部空格
	 * 
	 * @param in
	 * @return
	 */
	public static String removeLeadingAndTrailingSpaces(String in) {
		return removeLeadingSpaces(removeTrailingSpaces(in));
	}

	/**
	 * 获取行
	 * 
	 * @param s
	 * @return
	 */
	public static int getRows(String s) {
		if (s == null)
			return 0;
		else {
			int count = 1;
			int length = s.length();
			for (int i = 0; i < length; i++)
				if (s.charAt(i) == '\n')
					count++;
			return count;
		}
	}
}